<?php
class RegisterController extends Zend_Controller_Action{
	public function indexAction(){
		$registerForm = new Application_Form_Register($this->_helper->Section->getSectArray());
		$registerForm->setAction($this->view->url(array('controller' => 'register', 'action' => 'register'),'default',true));
		$this->view->form = $registerForm;
	}
	public function registerAction(){
		$request = $this->getRequest();
		if($request->isPost()){
			$form = new Application_Form_Register($this->_helper->Section->getSectArray());
			$data = $request->getPost();
			if($form->isValid($data)){
				//@TODO Enregistrer user
				$values = $form->getValues();
				$values['password'] = md5($values['password']);
				
				$user = new Application_Model_User($values);
				$mapper = new Application_Model_UserMapper();
				$mapper->save($user);
				
				$this->_helper->redirector('done','register');
			}else{
				$this->view->form = $form;
			}
		}else{
			$this->_helper->redirector('index','news');
		}
	}
	public function doneAction(){
		$this->view->message = "Registration Success !";
	}
}